#include <gwbase/base/conf.h>
#include <gwbase/base/test_harness.h>

using namespace dicom;

class ConfTest {};

TEST(ConfTest, ParseEmpty) {
  Conf conf;
  Status s = conf.ParseString("");
  EXPECT_TRUE(s.ok());
}

TEST(ConfTest, ParseComment) {
  Conf conf;
  Status s = conf.ParseString("# commet");
  EXPECT_TRUE(s.ok());
}

TEST(ConfTest, ParseComment2) {
  Conf conf;
  Status s = conf.ParseString("   # commet");
  EXPECT_TRUE(s.ok());
}

TEST(ConfTest, KV1) {
  Conf conf;
  Status s = conf.ParseString("key1 = value\n");
  EXPECT_TRUE(s.ok());
  EXPECT_Eq(conf.GetString("", "key1", ""), "value");
}

TEST(ConfTest, KV2) {
  Conf conf;
  Status s = conf.ParseString("key1 = value #comment");
  EXPECT_TRUE(s.ok());
  EXPECT_Eq(conf.GetString("", "key1", ""), "value");
}

TEST(ConfTest, KV3) {
  Conf conf;
  Status s = conf.ParseString("key1 =false#comment");
  EXPECT_TRUE(s.ok());
  EXPECT_Eq(conf.GetBool("", "key1", true), false);
}

TEST(ConfTest, DupKey) {
  Conf conf;
  Status s = conf.ParseString("key1 =value1\nkey1=value2#comment");
  EXPECT_TRUE(s.ok());
  EXPECT_Eq(conf.GetString("", "key1", ""), "value2");
}

TEST(ConfTest, KV) {
  Conf conf;
  Status s =
      conf.ParseString("key=value\nkey1 = value #comment \nkey2= value\n\n");
  EXPECT_TRUE(s.ok());
  EXPECT_Eq(conf.GetString("", "key", ""), "value");
  EXPECT_Eq(conf.GetString("", "key1", ""), "value");
  EXPECT_Eq(conf.GetString("", "key2", ""), "value");
}

TEST(ConfTest, Section1) {
  Conf conf;
  Status s = conf.ParseString("[s1]\nkey1 =value#comment\n[s2]\nkey1=value2\n");
  EXPECT_TRUE(s.ok());
  EXPECT_Eq(conf.GetString("s1", "key1", ""), "value");
  EXPECT_Eq(conf.GetString("s2", "key1", ""), "value2");
}

int main() { RunAllTests(); }
